package com.wrs.project.androiddemo

import android.Manifest
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import com.qiniu.droid.rtplayer.QNDecodeMode
import com.qiniu.droid.rtplayer.QNError
import com.qiniu.droid.rtplayer.QNLogLevel
import com.qiniu.droid.rtplayer.QNRTPlayer
import com.qiniu.droid.rtplayer.QNRTPlayerFactory
import com.qiniu.droid.rtplayer.QNRTPlayerSetting
import com.qiniu.droid.rtplayer.QNRTPlayerUrl
import com.qiniu.droid.rtplayer.render.QNSurfaceView


//import com.wrs.project.module.face.custom.FaceEngine

class MainActivity : ComponentActivity() {
    // 通过startActivityForResult方式拉起授权流程界面的请求码，具体数值开发者可以自行定义
    val tag = "MainActivity======="

  lateinit var  surfaceView: QNSurfaceView
    private var mRTPlayer: QNRTPlayer? = null
    private var mRTUrl = QNRTPlayerUrl()
    private var mRTPlayerSetting: QNRTPlayerSetting? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_main)

surfaceView = findViewById<QNSurfaceView>(R.id.qn_video_view)
        this.mRTPlayer = QNRTPlayerFactory.createQNRTPlayer(this)
        mRTPlayerSetting = QNRTPlayerSetting()
            .setLogLevel(QNLogLevel.INFO)
            .setDecodeMode(QNDecodeMode.SOFTWARE)
//            .setJitterBufferMinimumDelay(Math.round(jitterBufferMinDelay * 100) as Double / 100)
        mRTPlayer?.initPlayer(mRTPlayerSetting)
        mRTPlayer?.setEventListener(object : QNRTPlayer.EventListener{
            override fun onPlayerStateChanged(p0: Int) {
                Log.e("",  "${p0}")
            }

            override fun onPlayerInfo(p0: Int, p1: Any?) {

            }

            override fun onPlayerError(p0: QNError?) {
                Log.e("onPlayerError",  "${p0}")
            }

        })
        mRTPlayer?.setSurfaceRenderWindow(surfaceView)
        mRTUrl.setURL("webrtc://livecyz.chaoezu.top:447/chaoezu/wawaji10");
        mRTUrl.isHttpPost = false
        mRTPlayer?.playUrl(mRTUrl);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(
                arrayOf<String>(
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                ), 100
            )
        }
    }


}

